﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SnippetBox.Core.Common.Paging;
using SnippetBox.Core.Data.Models;

namespace SnippetBox.Web.Models {
    public class SearchModel {
        public IPagedList<Snippet> Snippets { get; set; }
        public IPagedList<Category> Categories { get; set; }
        public string SearchQuery { get; set; }

        public SearchModel() {}

        public SearchModel(string searchQuery, IPagedList<Snippet> snippets, IPagedList<Category> categories) {
            SearchQuery = searchQuery;
            Snippets = snippets;
            Categories = categories;
        }

        public bool IsEmptyResults { 
            get {
                if (Snippets == null && Categories == null)
                    return true;

                return !Snippets.Any() && !Categories.Any();
            } 
        }

        public int SearchResultsCount {
            get { return Snippets.TotalItemCount + Categories.Count; }
        }
    }
}